package com.cet.lxf.collection.test07;

import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Properties;

/**
 * @program: algorithm
 * @description:
 * @author: 陈恩涛
 * @create: 2021-08-12 16:52
 **/
public class Main01 {
    public static void main(String[] args) throws IOException {
        Properties pro = new Properties();
        // 绝对路径
        String abPathName = "F:\\学习笔记\\algorithm\\src\\com\\cet\\lxf\\collection\\test07\\setting.properties";
//		pro.load(new FileInputStream(pro_name1));
        // 优点，解决默认是ASCII码，中文乱码情况，支持jdk 9.0以上
        pro.load(new FileReader(abPathName, StandardCharsets.UTF_8));
//		// classpath 相对路径
        String pathName = "./setting1.properties";
        pro.load(Main01.class.getResourceAsStream(pathName));

        // 读取配置字段
        System.out.println(pro.getProperty("APP_ID"));
        System.out.println(pro.getProperty("log_path"));

        // 写入配置文件
        pro.setProperty("mac", "LAKDL989KDFJLAJFLJDSA");
        // 保存，更新
        pro.store(new FileOutputStream(abPathName), "注释： 配置文件注释环境配置");
        System.out.println("LAKDL989KDFJLAJFLJDSA".equals(pro.getProperty("mac")) ? "god":"said");

    }
}
